// g++ -std=c++17
#include <exception>
#include <iostream>
using namespace std;

class Up
{
};
class Fit
{
};

void g();

void f(int i)
{
	switch (i)
	{
	case 1:
		throw Up();
	case 2:
		throw Fit();
	}
	g();
}

#ifdef USE_V1
void g()
{
	cout << "g() called" << endl;
}
#endif
void g()
{
	throw 42; // block it
}

void my_unexpected()
{
	cout << "unexcepted exception thrown" << endl;
	exit(0);
}

int main()
{
	set_unexpected(my_unexpected);
	for (int i = 1; i <= 3; i++)
		try
		{
			f(i);
		}
		catch (Up)
		{
			cout << "Up caught" << endl;
		}
		catch (Fit)
		{
			cout << "Fit caught" << endl;
		}
}